﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using PocketApplicationsMVC.Views;

namespace PocketApplicationsMVC.Managers
{
    public class ApplicationManager
    {
        #region fields

        private static ApplicationManager appManager;
        private Dictionary<string, IController> controllersCache;

        #endregion

        #region constructors

        static ApplicationManager()
        {
            // Create an instance of itself for a singleton 
            appManager = new ApplicationManager();
        }

        public ApplicationManager()
        {
            controllersCache = new Dictionary<string, IController>();
        }

        #endregion

        public static ApplicationManager Instance
        {
            get
            {
                return appManager;
            }
        }

        //public LoginForm GetLoginForm()
        //{
        //    if (!controllersCache.ContainsKey("Login"))
        //    {
        //        controllersCache.Add("Login", new LoginController(new LoginForm()));
        //    }

        //    return controllersCache["Login"].View as LoginForm;
        //}

        //public void ShowLoginForm()
        //{
        //    if (!controllersCache.ContainsKey("Login"))
        //    {
        //        controllersCache.Add("Login", new LoginController(new LoginForm()));
        //    }
        //    controllersCache["Login"].View.Show();
        //}




        public MenuForm GetMenuForm()
        {
            if (!controllersCache.ContainsKey("Menu"))
            {
                controllersCache.Add("Menu", new MenuController(new MenuForm()));
            }
            return controllersCache["Menu"].View as MenuForm;
        }

        public void ShowMenuForm()
        {
            if (!controllersCache.ContainsKey("Menu"))
            {
                controllersCache.Add("Menu", new MenuController(new MenuForm()));
            }
            controllersCache["Menu"].View.Show();

        }

        public BoxNetForm GetBoxNetForm()
        {
            if (!controllersCache.ContainsKey("BoxNet"))
            {
                controllersCache.Add("BoxNet", new BoxNetController(new BoxNetForm()));
            }
            return controllersCache["BoxNet"].View as BoxNetForm;

        }

        public void ShowBoxNetForm()
        {
            if (!controllersCache.ContainsKey("BoxNet"))
            {
                controllersCache.Add("BoxNet", new BoxNetController(new BoxNetForm()));
            }
            controllersCache["BoxNet"].View.Show();
        }
    }
}
